﻿using System.Security.Cryptography;
using System.Text;

namespace KBWebApi.Common
{
    /// <summary>
    /// md5加密类
    /// </summary>
    public class MD5Provider
    {
        private MD5Provider()
        { }
        public static string Hash(string meg)
        {
            if(string.IsNullOrEmpty(meg))
            {
                return string.Empty;
            }
            else
            {
                MD5 md5 = MD5.Create();
                byte[] source = Encoding.Unicode.GetBytes(meg);
                byte[] result = md5.ComputeHash(source);
                StringBuilder buffer = new StringBuilder(result.Length);
                for(int i=0;i<result.Length;i++)
                {
                    buffer.Append(result[i].ToString("x"));
                }
                return buffer.ToString();
            }
        }
    }
}
